<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "good".
 *
 * @property int $id
 * @property string $name 商品名称
 * @property string $cover 商品封面图
 * @property int $cate_id 分类id
 * @property string $content 商品详情
 * @property int $is_zl 是否是租赁商品
 * @property string $unit 单位(租赁商品)
 * @property int $is_pay 是否需要支付
 * @property string $specs_ids 品类id集合
 * @property string $specs_obj_str
 * @property int $sort 优先级
 * @property int $type 类型(1:润园  2:三方)
 * @property string $imgs 图片合集(三方专有)
 * @property string $price 价格(三方专有)
 * @property string $contact_name 联系人姓名(三方专有)
 * @property string $contact_phone 联系人手机号(三方专有)
 * @property int $status 状态
 * @property int $created_at 创建时间
 */
class Good extends Base
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'good';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['cover'], 'required'],
            [['user_id', 'cate_id', 'is_zl', 'is_pay', 'is_have_specs', 'sort', 'type', 'unit_type', 'sale_count', 'status', 'audit_status', 'created_at'], 'integer'],
            [['content', 'specs_ids', 'specs_obj_str', 'imgs'], 'string'],
            [['price'], 'number'],
            [['name', 'cover', 'contact_name', 'contact_phone', 'audit_content'], 'string', 'max' => 255],
            [['unit'], 'string', 'max' => 32],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => 'Name',
            'cover' => 'Cover',
            'cate_id' => 'Cate ID',
            'content' => 'Content',
            'is_zl' => 'Is Zl',
            'unit' => 'Unit',
            'is_pay' => 'Is Pay',
            'specs_ids' => 'Specs Ids',
            'specs_obj_str' => 'Specs Obj Str',
            'sort' => 'Sort',
            'type' => 'Type',
            'imgs' => 'Imgs',
            'price' => 'Price',
            'contact_name' => 'Contact Name',
            'contact_phone' => 'Contact Phone',
            'status' => 'Status',
            'created_at' => 'Created At',
        ];
    }

    public function getCate(){
        return $this->hasOne(Category::class, ['id' => 'cate_id']);
    }
}
